﻿
@{
    ViewBag.Title = "SPIndex";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}

<table id="Insiders_SPIndex_grid" class="easyui-datagrid" style="width:100%;" title="@ViewBag.NAME" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#Insiders_SPIndex_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="Insiders_SPIndex_tb" style="padding:2px 5px;">
    @*<input type="text" class="easyui-textbox" label="借阅人:" labelwidth="50px" style="width:180px" id="Insiders_SPIndex_txtName" />
    <input type="text" class="easyui-textbox" label="借阅档号:" labelwidth="70px" style="width:180px" id="Insiders_SPIndex_txtDH" />
    <input type="text" class="easyui-datebox" label="借阅起始时间:" labelwidth="90px" style="width:190px" id="Insiders_SPIndex_txtSTime" />
    <input type="text" class="easyui-datebox" label="借阅结束时间:" labelwidth="90px" style="width:190px" id="Insiders_SPIndex_txtETime" />
    <select class="easyui-combobox" label="审批状态:" labelwidth="60px" style="width:150px" id="Insiders_SPIndex_cmbSPStatus" editable="false" panelHeight="auto">
        <option value="-1">全部</option>
        <option value="0">未审批</option>
    </select>
    <a href="javascript:void(0);" id="Insiders_SPIndex_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="QUERY()" style="width:110px;height:30px;">查询</a>*@
    <a href="javascript:void(0);" id="Insiders_SPIndex_btnApp" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="Agree(1)" style="width:110px;height:30px;">同意</a>
    <a href="javascript:void(0);" id="Insiders_SPIndex_btnDis" class="easyui-linkbutton button-orange" iconCls="icon-redo" onclick="Agree(2)" style="width:110px;height:30px;">不同意</a>
</div>
<script>
    $(document).ready(function () {
        $('#Insiders_SPIndex_grid').datagrid({
            url: '/Insiders/Get_ajaxSPArchive?brrstatus=' +'@ViewBag.BrrStatus'+'&type=' + '@ViewBag.Type',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation();
    });
    @*function QUERY()
    {
        var name = $('#Insiders_SPIndex_txtName').val();
        var dh = $('#Insiders_SPIndex_txtDH').val();
        var type = $('#Insiders_SPIndex_cmbSPStatus').combobox('getValue');
        var stime = $('#Insiders_BrrHistory_txtSTime').datebox('getValue');
        var etime = $('#Insiders_SPIndex_txtETime').datebox('getValue');
        $('#Insiders_BrrHistory_grid').datagrid('options').url = '/Insiders/Get_ajaxBrrHistoryArchive?brrstatus=' + '@ViewBag.BrrStatus' + '&type=' + type + '&name=' + name + '&dh=' + dh + '&stime=' + stime + '&etime=' + etime;
        $('#Insiders_BrrHistory_grid').datagrid('load');
    }*@
    function Agree(result)
    {
        var rows = $('#Insiders_SPIndex_grid').datagrid('getChecked');
        if (rows.length == 0) {
            $.messager.alert('提示！', '请选择要审批的档案!', 'info');
            return false;
        }
        else {
            var id = [];
            for (var i = 0; i < rows.length; i++) {
               // alert(rows[i].BI_SPSTATUS);
                if (rows[i].BI_SPSTATUS != 0) {
                    $.messager.alert('提示！', '审批的档案在审批流程中，不能审批!', 'info');
                    return false;
                }
                else { id.push(rows[i].BI_ID); }
            } 
            var suggest = "";
            if (result == 2) {
                $.messager.prompt('提示', '请输入审批意见', function (r) {
                    if (r) {
                        $.ajax({
                            url: '/Insiders/SP',
                            type: 'post',
                            dataType: 'json',
                            data: { 'result': result, 'id': id, 'sg': r},
                            success: function (data) {
                                $.messager.alert('提示', '审批成功', 'info');
                                $('#Insiders_SPIndex_grid').datagrid('options').url = '/Insiders/Get_ajaxSPArchive?brrstatus=' + '@ViewBag.BrrStatus' + '&type=' + '@ViewBag.Type',
                                    $('#Insiders_SPIndex_grid').datagrid('load');
                            }
                        });
                    }
                })
            }
            else
            {
                $.ajax({
                    url: '/Insiders/SP',
                    type: 'post',
                    dataType: 'json',
                    data: { 'result': result, 'id': id, 'sg': suggest},
                    success: function (data) {
                        $.messager.alert('提示', '审批成功', 'info');
                        $('#Insiders_SPIndex_grid').datagrid('options').url = '/Insiders/Get_ajaxSPArchive?brrstatus=' + '@ViewBag.BrrStatus' + '&type=' + '@ViewBag.Type',
                            $('#Insiders_SPIndex_grid').datagrid('load');
                    }
                });
            }
        }
    }
   
    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }

    function formatStatus(value, row) {
        if (value == 0) {
            return "申请";
        }
        else if (value == 1) {
            return "借出";
        }
        else {
            return "结束";
        }
    }
    function formatSPValue(value, row) {
        if (value == 0) {
            return "未审批";
        }
        else if (value == 1) {
            return "通过";
        }
        else {
            return "拒绝";
        }   
    }
    function formatSPStatus(value, row) {
        if (value == 0) {
            return "未审批";
        }
        else if (value == 1) {
            return "已审批";
        }
        else if (value == 2)
        {
            return "流程中(本部门审批)";
        }
        else {
            return "流程中(归档部门审批)";
        }
    }
    function InitPagenation() {
        //设置分页控件
        var p = $('#Insiders_SPIndex_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#Insiders_SPIndex_grid').datagrid('options').url = '/Insiders/Get_ajaxSPArchivePager?num=' + num + '&size=' + size;
        $('#Insiders_SPIndex_grid').datagrid('reload');
        $('#Insiders_SPIndex_grid').datagrid('options').pageNumber = num;
        $('#Insiders_SPIndex_grid').datagrid('options').pageSize = size;
        return;
    }
</script>


